package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.bean.Student;
import com.itheima.bean.User;
import com.itheima.mapper.StudentMapper;
import com.itheima.mapper.UserMapper;
import com.itheima.service.StudentService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.io.InputStream;
@Service("studentService")
@Transactional
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 分页查询方法
     * @param currentPage 当前页数
     * @param pageSize 每页展示条数
     * @return
     */
    @Override
    @Transactional(readOnly = true)
    public PageInfo<Student> selectByPage(int currentPage, int pageSize) {
        //设置分页参数
        PageHelper.startPage(currentPage,pageSize);
        //调用mapper方法查询所有
        Page<Student> page = studentMapper.findAll();
        //封装pageInfo对象,返回结果
        return new PageInfo<>(page);
    }

    /**
     * 添加学生信息
     * @param student
     * @return
     */
    @Override
    public int addStudent(Student student) {
        return studentMapper.addStudent(student);
    }

    /**
     * 修改学生的方法
     * @param student
     * @return
     */
    @Override
    public int updateStudent(Student student) {
        return studentMapper.updateStudent(student);
    }

    /**
     * 删除学生的方法
     * @param number
     * @return
     */
    @Override
    public int deleteStudent(String number) {
        return studentMapper.deleteStudent(number);
    }
}
